<!DOCTYPE html>
<html  xmlns:th="http://www.thymeleaf.org">
<head>
    <META HTTP-EQUIV="pragma" CONTENT="no-cache" >
    <META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate" >
    <META HTTP-EQUIV="expires" CONTENT="0" >
    <link rel="stylesheet" th:href="@{/adminlte/layui/css/layui.css}"  media="all"/>
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>
<!--<div class="layui-btn-group demoTable">
    <button class="layui-btn" data-type="getCheckData">获取选中行数据</button>
    <button class="layui-btn" data-type="getCheckLength">获取选中数目</button>
    <button class="layui-btn" data-type="isAll">验证是否全选</button>
</div>-->
<!--<h3 style="margin-top: -10px; margin-left:-10px;">检测入库</h3>-->
<div class="demoTable">
    主板编号：
    <div class="layui-inline" style="width: 210px">
        <input class="layui-input"  id="mainBoardNum" autocomplete="off" style="width: 200px;height: 25px" placeholder="请输入主板编号"/>
    </div>
    通讯编号：
    <div class="layui-inline" style="width: 210px;">
        <input class="layui-input"  id="telNum" autocomplete="off" style="width: 200px;height: 25px" placeholder="请输入通讯编号"/>
    </div>
    起始日期：
    <div class="layui-inline" style="width: 210px">
        <input class="layui-input"  id="startDateSearch" autocomplete="off" style="width: 200px;height: 25px" placeholder="请选择起始日期"/>
    </div>
    截止日期：
    <div class="layui-inline" style="width: 210px">
        <input class="layui-input"  id="endDateSearch" autocomplete="off" style="width: 200px;height: 25px" placeholder="请选择截止日期"/>
    </div>
    <button class="layui-btn layui-btn-sm" data-type="reload">查询</button>
</div>
<div id="add-mainDistributNumber" style="display: none;">
    <div class="my-form">
        <div class="layui-form-item my-form-item" style="margin-top: 10px">
            <label class="layui-form-label layui-icon" style="width: 170px" >通讯编号:</label>
            <div class="layui-input-inline">
                <input class="layui-input"  id="telNums" autocomplete="off" placeholder="请输入通讯编号" onkeyup="value=value.replace(/[^\d]/g,'')" onblur="telNumSerch()" />
                <p id="telNumsP" style="color: red; display: none" >通讯编号已被使用</p>
            </div>
        </div>
        <div class="layui-form-item my-form-item" style="margin-top: 10px">
            <label class="layui-form-label layui-icon" style="width: 170px">控制主板编号:</label>
            <div class="layui-input-inline">
                <input class="layui-input"  id="controlMainBoardNum" autocomplete="off" placeholder="请输入控制主板编号" onkeyup="value=value.replace(/[^\d]/g,'')" onblur="controlMainBoardNumSerch()" />
                <p id="controlMainBoardNumP" style="color: red; display: none" >控制主板编号已被使用</p>
                <p id="controlMainBoardNumPP" style="color: red; display: none" >控制主板编号不存在</p>
            </div>
        </div>
        <div class="layui-form-item my-form-item" style="margin-top: 10px">
            <label class="layui-form-label layui-icon" style="width: 170px">通讯主板编号:</label>
            <div class="layui-input-inline">
                <input class="layui-input"  id="telMainBoardNum" autocomplete="off" placeholder="请输入通讯主板编号" onkeyup="value=value.replace(/[^\d]/g,'')" onblur="telMainBoardNumSerch()"/>
                <p id="telMainBoardNumP" style="color: red; display: none" >通讯主板编号已被使用</p>
                <p id="telMainBoardNumPP" style="color: red; display: none" >通讯主板编号不存在</p>
            </div>
        </div>
        <div class="layui-form-item my-form-item">
            <label class="layui-form-label layui-icon" style="width: 170px">485主板编号:</label>
            <div class="layui-input-inline">
                <input class="layui-input"  id="fourMainBoardNum" autocomplete="off" placeholder="请输入485主板编号" onkeyup="value=value.replace(/[^\d]/g,'')" onblur="fourMainBoardNumSerch()"/>
                <p id="fourMainBoardNumP" style="color: red; display: none" >485主板编号已被使用</p>
                <p id="fourMainBoardNumPP" style="color: red; display: none" >485主板编号不存在</p>
            </div>
        </div>
        <div class="layui-form-item my-form-item">
            <label class="layui-form-label layui-icon" style="width: 170px">备注:</label>
            <div class="layui-input-inline">
                <input class="layui-input"  id="remarks" autocomplete="off" placeholder="请输入备注" />
            </div>
        </div>
    </div>
</div>
<script type="text/html" id="toolbarDemoDistrobut">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="addDistributNumber" >添加</button>
       <!-- <button class="layui-btn layui-btn-sm" lay-event="update" id="update" >修改</button>-->
        <button class="layui-btn layui-btn-sm" lay-event="deleteDistributNumber"  >删除</button>
      <!--  <button class="layui-btn layui-btn-sm" lay-event="upload" id="upload" >导入</button>-->
    </div>
</script>
<table class="layui-table" lay-data="{url:'/production/queryDistributNumber', page:true, id:'idTestDistributNumber',toolbar:'#toolbarDemoDistrobut',defaultToolbar:['filter', 'print','exports'] }" lay-filter="distributNumber">
    <thead>
    <tr>
        <th lay-data="{type:'checkbox', fixed: 'left'}"></th>
        <th lay-data="{field:'telNum', width:150}">通讯编号</th>
        <th lay-data="{field:'controlMainNum', width:180}">控制主板编号</th>
        <th lay-data="{field:'telMainNum', width:180}">通讯主板编号</th>
        <th lay-data="{field:'fourMainNum', width:180}">485主板编号</th>
        <th lay-data="{field:'status', width:150 }">产品状态</th>
        <th lay-data="{field:'operator', width:150}">操作人</th>
        <th lay-data="{field:'operatorTime', width:180}">操作时间</th>
        <th lay-data="{field:'remarks', width:500}">备注</th>
    </tr>
    </thead>
</table>

<script th:src="@{/adminlte/layui/layui.js}" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
    layui.use('table', function(){
        var table = layui.table;
        //监听表格复选框选择
    /*    table.on('checkbox(demo)', function(obj){
            console.log(obj)
        });
        //监听工具条
        table.on('tool(demo)', function(obj){
            var data = obj.data;
            if(obj.event === 'detail'){
                layer.msg('ID：'+ data.id + ' 的查看操作');
            } else if(obj.event === 'del'){
                layer.confirm('真的删除行么', function(index){
                    obj.del();
                    layer.close(index);
                });
            } else if(obj.event === 'edit'){
                /!*layer.alert('编辑行：<br/>'+ JSON.stringify(data))*!/

            }
        });*/
        //监听头工具栏事件
        table.on('toolbar(distributNumber)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id)
                ,data = checkStatus.data//获取选中的数据
                ,deList=[1];
            data.forEach(function (n,i) {
                deList.push(n.id)
            });
            deList.push(2);
            switch(obj.event){
                case 'addDistributNumber':
                    layer.open({
                        type:1,
                        title:'添加',
                        btnAlign: 'c',
                        area: ['500px', '350px'],
                        content: $("#add-mainDistributNumber"),
                        btn:['保存','取消'],
                        yes:function(index,layero){
                            var controlMainNum =top.$('#controlMainBoardNum').val();
                            var telNums =top.$('#telNums').val();
                            var telMainNum =top.$("#telMainBoardNum").val();
                            var fourMainNum =top.$("#fourMainBoardNum").val();
                            var remarks =top.$("#remarks").val();
                            if (controlMainNum=="") {
                                layer.msg('请输入控制主板编号！', {
                                    btnAlign: 'c',
                                    time: 3000, //20s后自动关闭
                                    btn: ['确定']
                                });
                            }else{
                                $.ajax({
                                    //几个参数需要注意一下
                                    type: "POST",//方法类型
                                    dataType: "json",//预期服务器返回的数据类型
                                    url: "/production/addDistributNumberMapper" ,//url
                                    data: {telNum:telNums,controlMainNum:controlMainNum,telMainNum:telMainNum,fourMainNum:fourMainNum,remarks:remarks},
                                    success: function (result) {
                                        console.log(result);//打印服务端返回的数据(调试用)
                                        if (result.success >0) {
                                            layer.msg('操作成功', {
                                                btnAlign: 'c',
                                                time: 3000, //20s后自动关闭
                                                btn: ['确定']
                                            });
                                            table.reload('idTestDistributNumber');
                                        }else{
                                            /* alert("系统错误");*/
                                            layer.msg('操作失败', {
                                                btnAlign: 'c',
                                                time: 3000, //20s后自动关闭
                                                btn: ['确定']
                                            });
                                        }
                                    },
                                    error : function() {
                                        alert("异常！");
                                    }
                                });

                                layer.close(index);
                            }

                        },
                        btn2:function (index) {
                            layer.close(index);
                        }
                    })
                    break;
             /*   case 'update':
                    if(data.length === 0){
                        layer.msg('请选择一行');
                    } else if(data.length > 1){
                        layer.msg('只能同时编辑一个');
                    } else {
                        var id =checkStatus.data[0].id;
                        layer.open({
                            type:1,
                            title:'修改',
                            btnAlign: 'c',
                            area: ['500px', '600px'],
                            content: $("#add-main"),
                            btn:['保存','取消'],
                            success: function (layero, index) {
                                top.$('#produceDateAdd').val(checkStatus.data[0].goodsProduceDate);
                                top.$('#numsAdd').val(checkStatus.data[0].goodsNums);
                                top.$('#operatorsAdd').val(checkStatus.data[0].operators);
                                top.$('#CardNumsAdd').val(checkStatus.data[0].cardNums);
                                top.$('#IMSIAdd').val(checkStatus.data[0].iMSI);
                                top.$('#IMEIAdd').val(checkStatus.data[0].iMEI);
                                top.$('#ICCIDAdd').val(checkStatus.data[0].iCCID);
                                top.$('#remarksAdd').val(checkStatus.data[0].remarks);
                            },
                            yes:function(index,layero){
                                var local =top.$('#localAdd').val();
                                var supplierNameAdd =top.$("#supplierNameAdd").val();
                                var goodsNameAdd =top.$("#goodsNameAdd option:selected").text();
                                var goodsType =top.$("#goodsTypeAdd option:selected").text();
                                var specifications =top.$("#specificationsAdd option:selected").text();
                                var produceDate =top.$("#produceDateAdd").val();
                                var nums =top.$("#numsAdd").val();
                                var pipelineNumberStart =top.$("#pipelineNumberStart").val();
                                var pipelineNumberEnd =top.$("#pipelineNumberEnd").val();
                                var operators =top.$("#operatorsAdd").val();
                                var CardNums =top.$("#CardNumsAdd").val();
                                var IMSI =top.$("#IMSIAdd").val();
                                var IMEI =top.$("#IMEIAdd").val();
                                var ICCID =top.$("#ICCIDAdd").val();
                                var remark =top.$("#remarksAdd").val();
                                $.ajax({
                                    //几个参数需要注意一下
                                    type: "POST",//方法类型
                                    dataType: "json",//预期服务器返回的数据类型
                                    url: "/goodsInStock/updateGoodsInStock" ,//url
                                    data: {local:local,goodsType:goodsType,goodsName:goodsNameAdd,supplierName:supplierNameAdd,specifications:specifications,goodsProduceDate:produceDate,goodsNums:nums,pipelineNumberStart:pipelineNumberStart,pipelineNumberEnd:pipelineNumberEnd,operators:operators,cardNums:CardNums,
                                        IMSI:IMSI,IMEI:IMEI,ICCID:ICCID,remarks:remark,id:id},
                                    success: function (result) {
                                        console.log(result);//打印服务端返回的数据(调试用)
                                        if (result.success >0) {
                                            alert("操作成功");
                                            table.reload('idTest');
                                        }else{
                                            alert("操作失败");
                                        }
                                    },
                                    error : function() {
                                        alert("异常！");
                                    }
                                });
                                layer.close(index);
                            },
                            btn2:function (index) {
                                layer.close(index);
                            }
                        })
                    }
                    break;*/
                case 'deleteDistributNumber':
                    if(data.length === 0){
                        layer.msg('请选择一行');
                    } else {
                        layer.confirm('确定删除',{btn: ['确定', '取消'], title: "提示"},function(index){
                            $.ajax({
                                //几个参数需要注意一下
                                type: "POST",//方法类型
                                dataType: "json",//预期服务器返回的数据类型
                                url: "/production/deleteDistributNumberMapper" ,//url
                                data: { deList:JSON.stringify(deList)},
                                success: function (result) {
                                    if (result.success>0) {
                                       /* alert("操作成功");*/
                                        layer.msg('操作成功', {
                                            btnAlign: 'c',
                                            time: 10000, //20s后自动关闭
                                            btn: ['确定']
                                        });
                                        table.reload('idTestDistributNumber')
                                    }else{
                                      /*  alert("系统错误");*/
                                        layer.msg('操作失败', {
                                            btnAlign: 'c',
                                            time: 10000, //20s后自动关闭
                                            btn: ['确定']
                                        });
                                    }
                                },
                                error : function() {
                                    alert("异常！");
                                }
                            });
                            layer.close(index);
                        });
                    }
                    break;
            }
        });
        var $ = layui.$, active = {
            reload:function () {
                var telNum=$("#telNum").val();
                var mainBoardNum=$("#mainBoardNum").val();
                var startDate=$("#startDateSearch").val();
                var endDate=$("#endDateSearch").val();
                table.reload('idTestDistributNumber',{
                    url:'/production/distributNumberSearch',
                    where:{telNum:telNum,mainBoardNum:mainBoardNum,startDate:startDate,endDate:endDate}  ,
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                })

            }
        };

        $('.demoTable .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });
    layui.use('laydate', function(){
        var laydate = layui.laydate;
        laydate.render({
            elem: '#startDateSearch' //指定元素
            ,type: 'datetime'
        });
        laydate.render({
            elem: '#endDateSearch' //指定元素
            ,type: 'datetime'
        });
    });
    layui.use(['upload'],function(){
        var $ = layui.jquery,
            upload = layui.upload;
//指定允许上传的文件类型
        upload.render({
            elem: '#upload'
            ,url: '/production/upload'
            ,accept: 'file' //普通文件
            ,exts: 'xlsx' //只允许上传excel文件
            ,done: function(res){
                if(res.code == 0){ //上传成功
                    layer.msg(res.msg);
                    table.reload('idTestDistributNumber')
                }else{
                    layer.msg('上传失败');
                }
            }
            ,error: function(index, upload){
                layer.msg('上传失败');
            }
        });
    });
    function telNumSerch() {
    var telNums=$("#telNums").val()
    $.ajax({
        //几个参数需要注意一下
        type: "POST",//方法类型
        dataType: "json",//预期服务器返回的数据类型
        url: "/production/telNumsP" ,//url
        data: {telNum:telNums},
        success: function (result) {
            console.log(result);//打印服务端返回的数据(调试用)
            if (result.exist >0) {
                $("#telNumsP").show();
                $("#telNums").val("");
            }else{
                $("#telNumsP").hide();
            }
        },
        error : function() {
            alert("异常！");
        }
    });

}
    function controlMainBoardNumSerch() {
        var controlMainBoardNum=$("#controlMainBoardNum").val()
        $.ajax({
            //几个参数需要注意一下
            type: "POST",//方法类型
            dataType: "json",//预期服务器返回的数据类型
            url: "/production/controlP" ,//url
            data: {controlMainBoardNum:controlMainBoardNum},
            success: function (result) {
                console.log(result);//打印服务端返回的数据(调试用)
                if (result.exist >0) {
                    $("#controlMainBoardNumP").show();
                    $("#controlMainBoardNum").val("");
                }else{
                    $("#controlMainBoardNumP").hide();
                }
            },
            error : function() {
                alert("异常！");
            }
        });
        $.ajax({
            //几个参数需要注意一下
            type: "POST",//方法类型
            dataType: "json",//预期服务器返回的数据类型
            url: "/goodsInStock/controlMainBoardNum" ,//url
            data: {controlMainBoardNum:controlMainBoardNum},
            success: function (result) {
                console.log(result);//打印服务端返回的数据(调试用)
                if (result.exist >0) {
                    $("#controlMainBoardNumPP").show();
                    $("#controlMainBoardNum").val("");
                }else{
                    $("#controlMainBoardNumPP").hide();
                }
            },
            error : function() {
                alert("异常！");
            }
        });
    }
    function telMainBoardNumSerch() {
        var telMainBoardNum=$("#telMainBoardNum").val()
        $.ajax({
            //几个参数需要注意一下
            type: "POST",//方法类型
            dataType: "json",//预期服务器返回的数据类型
            url: "/production/telP" ,//url
            data: {telMainBoardNum:telMainBoardNum},
            success: function (result) {
                console.log(result);//打印服务端返回的数据(调试用)
                if (result.exist >0) {
                    $("#telMainBoardNumP").show();
                    $("#telMainBoardNum").val("");
                }else{
                    $("#telMainBoardNumP").hide();
                }
            },
            error : function() {
                alert("异常！");
            }
        });
        $.ajax({
            //几个参数需要注意一下
            type: "POST",//方法类型
            dataType: "json",//预期服务器返回的数据类型
            url: "/goodsInStock/telMainBoardNum" ,//url
            data: {telMainBoardNum:telMainBoardNum},
            success: function (result) {
                console.log(result);//打印服务端返回的数据(调试用)
                if (result.exist >0) {
                    $("#telMainBoardNumPP").show();
                    $("#telMainBoardNum").val("");
                }else{
                    $("#telMainBoardNumPP").hide();
                }
            },
            error : function() {
                alert("异常！");
            }
        });

    }
    function fourMainBoardNumSerch() {
        var fourMainBoardNum=$("#fourMainBoardNum").val()
        $.ajax({
            //几个参数需要注意一下
            type: "POST",//方法类型
            dataType: "json",//预期服务器返回的数据类型
            url: "/production/fourP" ,//url
            data: {fourMainBoardNum:fourMainBoardNum},
            success: function (result) {
                console.log(result);//打印服务端返回的数据(调试用)
                if (result.exist >0) {
                    $("#fourMainBoardNumP").show();
                    $("#fourMainBoardNum").val("");
                }else{
                    $("#fourMainBoardNumP").hide();
                }
            },
            error : function() {
                alert("异常！");
            }
        });
        $.ajax({
            //几个参数需要注意一下
            type: "POST",//方法类型
            dataType: "json",//预期服务器返回的数据类型
            url: "/goodsInStock/fourMainBoardNum" ,//url
            data: {fourMainBoardNum:fourMainBoardNum},
            success: function (result) {
                console.log(result);//打印服务端返回的数据(调试用)
                if (result.exist >0) {
                    $("#fourMainBoardNumPP").show();
                    $("#fourMainBoardNum").val("");
                }else{
                    $("#fourMainBoardNumPP").hide();
                }
            },
            error : function() {
                alert("异常！");
            }
        });
    }
    var unSelected = "#999";
    var selected = "#333";
    $(function () {
        $("select").css("color", unSelected);
        $("option").css("color", selected);
        $("select").change(function () {
            var selItem = $(this).val();
            if (selItem == $(this).find('option:first').val()) {
                $(this).css("color", unSelected);
            } else {
                $(this).css("color", selected);
            }
        });
    })
</script>

</body>
</html>